<template>
  <div>
    <el-card class="box-card" style="opacity: 0.8;">
      <div slot="header" class="clearfix" style="font-size: 18px">
        <i class="el-icon-s-grid"></i>
        <span>数据矩阵</span>
      </div>
      <el-table :data="idType" stripe style="width: 100%" border>
        <el-table-column prop="papersname" label="名称" width="213">
        </el-table-column>
        <el-table-column
          v-for="(item, index) in AccountType"
          prop="account"
          :label="item.account"
          :key="index"
        >
         <template slot-scope="scope">
						<el-checkbox v-if="scope.row.aids.indexOf(item.accountid) != -1" checked  @change="checkeds(item.accountid, scope.row.papersid)"></el-checkbox>
						<el-checkbox v-if="scope.row.aids.indexOf(item.accountid) === -1" @change="checkeds(item.accountid, scope.row.papersid)"></el-checkbox>
					</template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[1, 3, 5, 10]"
        :page-size="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import qs from "qs";
export default {
  data() {
    return {
      AccountType: [],
      queryinfo: {
        pagenum: 1, //访问的页码
        pagesize: 3, //默认页面展示的条数
      },
      idType: [],
      AccountTypeAndidType: [],
      pd: 0,
      accountTypeIdType: {
        accountid: "",
        papersid: "",
      },
      total: 0,
    };
  },
  methods: {
    async selectAccountType() {
      var res = await this.$http.post("/selectAllAccountType");
      if (res.data.code == 200) {
        this.AccountType = res.data.data;
      } else {
        this.$message.info(res.data.message);
      }
    },
    async selectAllIdType() {
      this.idType=[]
      var param = new URLSearchParams();
      param.append("pagenum", this.queryinfo.pagenum);
      param.append("pagesize", this.queryinfo.pagesize);
      var res = await this.$http.post("/selectAllIdTypeAndZj", param);
      if (res.data.code != "200") {
        this.$message.info(res.data.message);
      } else {
        //把查询到的集合数据放入全局的users对象中
        for (const item of res.data.data.list) {
            if(item.aids===null){
              item.aids = ""
            }
        }
        this.idType = res.data.data.list;
        //获取数据的总条数
        this.total = res.data.data.total;
      }
    },
    async selectAllAccountTypeAndidType() {
      var res = await this.$http.post("/selectAllAccountTypeAndidType");
      if (res.data.code == 200) {
        this.AccountTypeAndidType = res.data.data;
      } else {
        this.$message.info(res.data.message);
      }
    },
    async checkeds(accountid, papersid) {
      // console.log(accountid,papersid)
      this.accountTypeIdType.accountid = accountid;
      this.accountTypeIdType.papersid = papersid;
      var res = await this.$http.post(
        "updateAccountTypeAndidType",
        qs.stringify(this.accountTypeIdType)
      );
    },
    handleSizeChange(newpagesize) {
      this.queryinfo.pagesize = newpagesize;
      this.selectAllIdType();
      this.selectAccountType();
  
    },
    handleCurrentChange(newpagenum) {
      this.queryinfo.pagenum = newpagenum;
      this.selectAllIdType();
      this.selectAccountType();
    },
  },
  mounted() {
    this.selectAllIdType();
    this.selectAccountType();
  },
};
</script>

<style scoped="scoped">
</style>